package app;

import data.dao.UserRepository;
import data.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/11/4.
 */
@Controller
public class ZuulController {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private HttpServletRequest request;

    @RequestMapping(value = "/logintest", method = RequestMethod.GET)
    @ResponseBody
    public UserEntity findUser(@RequestParam String userName, @RequestParam String password) {
        UserEntity user = userRepository.findByName(userName);
        if(user.getPassword().equals(password)){
            request.getSession().setAttribute("user",user);
        }
        return user;
    }
}
